<?php $this->_extends('_layouts/main_layout'); ?>
<?php $this->_block('title'); ?>
<?php echo "Add Campaign"; ?>
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>
<div id="content" class="box">
	<h1>Add Campaign</h1>
		<?php if (isset($infos)) 
				{
					foreach ($infos as $info)
					{
		?>
				<p class="msg info"><?php echo $info;?></p>
		<?php		}
				}
		?>
		<fieldset>
			<legend>Add Campaign</legend>
		<?php if (isset($errors)) 
				{
					foreach ($errors as $error)
					{
		?>
				<p class="msg error"><?php echo $error;?></p>
		<?php		}
				}
		?>
		
		<form method="post" action="<?php echo url('campaign/add');?>">
		<table class="nostyle">
			
			<?php if(null === $publishers): ?>
				<tr>
					<td colspan="2">
						<a href="<?php echo url('publisher/add'); ?>">Ops, there's no publisher yet, please click here to add new publisher</a>
					</td>
				</tr>
			<?php endif; ?>
			
			<tr>
				<td>Publisher</td>
				<td>
					<?php 
						echo Util::buildDropDownList(
						 	array('id'=>'publisher', 'name'=>'publisher'),
						 	$publishers,
						 	isset($publisher) ? $publisher : false,
						 	array('v'=>"",'l'=>'--Please select a publisher--')
						 );
					?>
				</td>
			</tr>
			<tr>
				<td>sub</td>
				<td>
					<select id="sub" name="sub">
						<option value="">--Please choose a sub--</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>Name:</td>
				<td><input type="text" class="input-text" name="name" value="<?php if (isset($name)) echo $name;?>"/></td>
			</tr>
			<?php if(null === $offers): ?>
			<tr>
				<td colspan="2">
					<a href="<?php echo url('offer/insert'); ?>">Ops, there's no offer yet, please click here to add new offer</a>
				</td>
			<?php endif; ?>
			</tr>
			<tr>
				<td>Offer</td>
				<td>
					<?php 
						echo Util::buildDropDownList(
						 	array('id'=>'offer', 'name'=>'offer'),
						 	$offers,
						 	isset($offer) ? $offer : false,
						 	array('v'=>"",'l'=>'--Please select an offer--')
						 );
					?>
				</td>
			</tr>
			<tr>
				<td>Pixel Type</td>
				<td>
					<select id="pixel_type" name="pixel_type">
						<option value="" >--Please choose --</option>
						<option value="0">Image</option>
						<option value="1">Iframe</option>
						<option value="2">Javascript</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>Pixel</td>
				<td><textarea name="pixel"></textarea></td>
			</tr>
			<tr>
				<td colspan="2" class="t-right"><input type="submit" class="input-submit" value="Add"/></td>
			</tr>
		</table>
		</form>
	</fieldset>
</div>
<script type="text/javascript">
	$(function(){
		$('#publisher').change(function(){
			$('#sub').children(':gt(0)').remove();
			var pid = $('#publisher').val();
			if('' == pid)
				return;
			$.get("<?php echo url('admin/loadsubs');?>", {id: pid}, function(data){
				var subs = eval('(' + data + ')');
				for(var i=0; i<subs.length; i++){
					var content = '<option value="'+subs[i]['id']+'">'+subs[i]['name']+'</option>';
					$(content).appendTo('#sub');
				}
			});
		});
	});
</script>
<?php $this->_endblock(); ?>
